

************************
** Study 2: Figure S2.13
************************



** 2017 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 pol_interest4 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2015_1 vote2015_2 vote2015_3 vote2015_4 vote2015_5 vote2015_6 vote2015_7 vote2015_8 vote2015_9 vote2015_10 refvote2016_1 refvote2016_2 refvote2016_3 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2017.dta", replace

* Young dummy
gen young = 1 if inrange(agecat,1,2)
replace young = 0 if inrange(agecat,3,6)

* University degree dummy
gen degree = 1 if inrange(edu,5,6)
replace degree = 0  if inrange(edu,1,4)

* Male dummy
gen male = 1 if gender == 2
replace male = 0 if gender == 1
replace male = 0 if gender == 3

* Leftist dummy
gen leftist = 1 if inrange(lr,0,4)
replace leftist = 0 if inrange(lr,5,10)

* Undecided dummy
gen undecided = 1 if voteint2017 == -995
replace undecided = 0 if voteint2017 !=. & voteint2017 != -995


* Regressions
foreach dv of varlist sec imm britid englid {
foreach mod of varlist young degree male leftist undecided {
reg `dv' i.postattack##i.`mod' $covars_binaries if statadate == td(02jun2017) | statadate == td(04jun2017)
estimates store `dv'1`mod'
	sum `mod' if `mod' == 1 & e(sample) == 1
	estadd local n1 `r(N)'
	sum `mod' if `mod' == 0 & e(sample) == 1
	estadd local n2 `r(N)'
reg `dv' i.postattack##i.`mod' $covars_binaries if inrange(statadate,td(01jun2017),td(02jun2017)) | inrange(statadate,td(04jun2017),td(05jun2017))
estimates store `dv'2`mod'
	sum `mod' if `mod' == 1 & e(sample) == 1
	estadd local n1 `r(N)'
	sum `mod' if `mod' == 0 & e(sample) == 1
	estadd local n2 `r(N)'
reg `dv' i.postattack##i.`mod' $covars_binaries if inrange(statadate,td(31may2017),td(02jun2017)) | inrange(statadate,td(04jun2017),td(06jun2017))
estimates store `dv'3`mod'
	sum `mod' if `mod' == 1 & e(sample) == 1
	estadd local n1 `r(N)'
	sum `mod' if `mod' == 0 & e(sample) == 1
	estadd local n2 `r(N)'
}
}



* Results table
gen count = _n in 1/20
gen days = _n - 1 in 2/4
replace days = _n - 5 in 6/8
replace days = _n - 9 in 10/12
replace days = _n - 13 in 14/16
replace days = _n - 17 in 18/20
gen label = "Young" in 1
replace label = "Degree" in 5
replace label = "Male" in 9
replace label = "Leftist" in 13
replace label = "Undecided" in 17
replace label = "1d/1d" if days == 1
replace label = "2d/2d" if days == 2
replace label = "3d/3d" if days == 3
foreach dv of varlist sec imm britid englid {
gen n1_`dv' = .
gen n2_`dv' = .
gen coef_`dv' = .
gen se_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
forvalues i = 1/3 {
estimates restore `dv'`i'young
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,2,4)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,2,4)
replace coef_`dv' = _b[1.postattack#1.young] if days == `i' & inrange(count,2,4)
replace se_`dv' = _se[1.postattack#1.young] if days == `i' & inrange(count,2,4)	
estimates restore `dv'`i'degree
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,6,8)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,6,8)
replace coef_`dv' = _b[1.postattack#1.degree] if days == `i' & inrange(count,6,8)
replace se_`dv' = _se[1.postattack#1.degree] if days == `i' & inrange(count,6,8)
estimates restore `dv'`i'male
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,10,12)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,10,12)
replace coef_`dv' = _b[1.postattack#1.male] if days == `i' & inrange(count,10,12)
replace se_`dv' = _se[1.postattack#1.male] if days == `i' & inrange(count,10,12)
estimates restore `dv'`i'leftist
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,14,16)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,14,16)
replace coef_`dv' = _b[1.postattack#1.leftist] if days == `i' & inrange(count,14,16)
replace se_`dv' = _se[1.postattack#1.leftist] if days == `i' & inrange(count,14,16)
estimates restore `dv'`i'undecided
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,18,20)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,18,20)
replace coef_`dv' = _b[1.postattack#1.undecided] if days == `i' & inrange(count,18,20)
replace se_`dv' = _se[1.postattack#1.undecided] if days == `i' & inrange(count,18,20)
}
replace ll_`dv' = coef_`dv' - 1.96*se_`dv'
replace ul_`dv' = coef_`dv' + 1.96*se_`dv'
replace d_`dv' = coef_`dv'/sd_`dv'
replace dlow_`dv' = coef_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv'
replace dup_`dv' = coef_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv'
}

drop newid - undecided
drop _est*
keep in 1/20
gen year = 2017
order year

save "SubGroup2017.dta", replace




** 2019 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2017_1 vote2017_2 vote2017_3 vote2017_4 vote2017_5 vote2017_6 vote2017_7 vote2017_8 vote2017_9 vote2017_10 vote2017_11 refvote2016_1 refvote2016_2 refvote2016_3 refvote2016_4 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2019.dta", replace

* Young dummy
gen young = 1 if inrange(agecat,1,2)
replace young = 0 if inrange(agecat,3,6)

* University degree dummy
gen degree = 1 if inrange(edu,5,6)
replace degree = 0  if inrange(edu,1,4)

* Male dummy
gen male = 1 if gender == 2
replace male = 0 if gender == 1
replace male = 0 if gender == 3

* Leftist dummy
gen leftist = 1 if inrange(lr,0,4)
replace leftist = 0 if inrange(lr,5,10)

* Undecided dummy
gen undecided = 1 if voteint2019 == -995
replace undecided = 0 if voteint2019 !=. & voteint2019 != -995


* Regressions
foreach dv of varlist sec imm britid englid {
foreach mod of varlist young degree male leftist undecided {
reg `dv' i.postattack##i.`mod' $covars_binaries if statadate == td(28nov2019) | statadate == td(30nov2019)
estimates store `dv'1`mod'
	sum `mod' if `mod' == 1 & e(sample) == 1
	estadd local n1 `r(N)'
	sum `mod' if `mod' == 0 & e(sample) == 1
	estadd local n2 `r(N)'
reg `dv' i.postattack##i.`mod' $covars_binaries if inrange(statadate,td(27nov2019),td(28nov2019)) | inrange(statadate,td(30nov2019),td(1dec2019))
estimates store `dv'2`mod'
	sum `mod' if `mod' == 1 & e(sample) == 1
	estadd local n1 `r(N)'
	sum `mod' if `mod' == 0 & e(sample) == 1
	estadd local n2 `r(N)'
reg `dv' i.postattack##i.`mod' $covars_binaries if inrange(statadate,td(26nov2019),td(28nov2019)) | inrange(statadate,td(30nov2019),td(2dec2019))
estimates store `dv'3`mod'
	sum `mod' if `mod' == 1 & e(sample) == 1
	estadd local n1 `r(N)'
	sum `mod' if `mod' == 0 & e(sample) == 1
	estadd local n2 `r(N)'
}
}


* Results table
gen count = _n in 1/20
gen days = _n - 1 in 2/4
replace days = _n - 5 in 6/8
replace days = _n - 9 in 10/12
replace days = _n - 13 in 14/16
replace days = _n - 17 in 18/20
gen label = "Young" in 1
replace label = "Degree" in 5
replace label = "Male" in 9
replace label = "Leftist" in 13
replace label = "Undecided" in 17
replace label = "1d/1d" if days == 1
replace label = "2d/2d" if days == 2
replace label = "3d/3d" if days == 3
foreach dv of varlist sec imm britid englid {
gen n1_`dv' = .
gen n2_`dv' = .
gen coef_`dv' = .
gen se_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
forvalues i = 1/3 {
estimates restore `dv'`i'young
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,2,4)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,2,4)
replace coef_`dv' = _b[1.postattack#1.young] if days == `i' & inrange(count,2,4)
replace se_`dv' = _se[1.postattack#1.young] if days == `i' & inrange(count,2,4)	
estimates restore `dv'`i'degree
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,6,8)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,6,8)
replace coef_`dv' = _b[1.postattack#1.degree] if days == `i' & inrange(count,6,8)
replace se_`dv' = _se[1.postattack#1.degree] if days == `i' & inrange(count,6,8)
estimates restore `dv'`i'male
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,10,12)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,10,12)
replace coef_`dv' = _b[1.postattack#1.male] if days == `i' & inrange(count,10,12)
replace se_`dv' = _se[1.postattack#1.male] if days == `i' & inrange(count,10,12)
estimates restore `dv'`i'leftist
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,14,16)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,14,16)
replace coef_`dv' = _b[1.postattack#1.leftist] if days == `i' & inrange(count,14,16)
replace se_`dv' = _se[1.postattack#1.leftist] if days == `i' & inrange(count,14,16)
estimates restore `dv'`i'undecided
replace n1_`dv' = `e(n1)' if days == `i' & inrange(count,18,20)
replace n2_`dv' = `e(n2)' if days == `i' & inrange(count,18,20)
replace coef_`dv' = _b[1.postattack#1.undecided] if days == `i' & inrange(count,18,20)
replace se_`dv' = _se[1.postattack#1.undecided] if days == `i' & inrange(count,18,20)
}
replace ll_`dv' = coef_`dv' - 1.96*se_`dv'
replace ul_`dv' = coef_`dv' + 1.96*se_`dv'
replace d_`dv' = coef_`dv'/sd_`dv'
replace dlow_`dv' = coef_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv'
replace dup_`dv' = coef_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv'
}

drop id - undecided
drop _est*
keep in 1/20
gen year = 2019
order year

save "SubGroup2019.dta", replace





** Figure
*********

* Data preparations
forvalues i = 1/3 {
foreach j in 2017 2019 {
use "SubGroup`j'.dta", replace
keep if days == `i' | days == . 
gen y_sec = 2 in 2
replace y_sec = 8 in 4
replace y_sec = 14 in 6
replace y_sec = 20 in 8
replace y_sec = 26 in 10
gen y_imm = y_sec + 1
gen y_britid = y_sec + 2
gen y_englid = y_sec + 3
order y_*
gen n_sec = n1_sec + n2_sec
gen n_imm = n1_imm + n2_imm
gen n_britid = n1_britid + n2_britid
gen n_englid = n1_englid + n2_e
tostring n_sec, replace
replace n_sec = "" if n_sec == "."
tostring n1_sec, replace
replace n1_sec = "" if n_sec == "."
tostring n_imm, replace
replace n_imm = "" if n_imm == "."
tostring n1_imm, replace
replace n1_imm = "" if n1_imm == "."
tostring n_britid, replace
replace n_britid = "" if n_britid == "."
tostring n1_britid, replace
replace n1_britid = "" if n1_britid == "."
tostring n_englid, replace
replace n_englid = "" if n_englid == "."
tostring n1_englid, replace
replace n1_englid = "" if n1_englid == "."
replace n_sec = "{it:N}" in 1
replace n1_sec = "{it:N{subscript:Young}}" in 1
replace n_sec = "{it:N}" in 3
replace n1_sec = "{it:N{subscript:Degree}}" in 3
replace n_sec = "{it:N}" in 5
replace n1_sec = "{it:N{subscript:Male}}" in 5
replace n_sec = "{it:N}" in 7
replace n1_sec = "{it:N{subscript:Leftist}}" in 7
replace n_sec = "{it:N}" in 9
replace n1_sec = "{it:N{subscript:Undecided}}" in 9
replace y_sec = 1 in 1
replace y_sec = 7 in 3
replace y_sec = 13 in 5
replace y_sec = 19 in 7
replace y_sec = 25 in 9
save "SubGroup`j'_`i'.dta", replace
}
}


* One-day comparison
use "SubGroup2017_1.dta", replace
append using "SubGroup2019_1.dta"
gen x1 = 12.5
gen x2 = 15.5
* Graph
twoway ///
	(scatter y_sec d_sec, mcolor(gs12) msymbol(o)) ///
	(rspike dlow_sec dup_sec y_sec, lcolor(gs12) horizontal) ///
	(scatter y_imm d_imm, mcolor(gs8) msymbol(s) msize(medsmall)) ///
	(rspike dlow_imm dup_imm y_imm, lcolor(gs8) horizontal lwidth(medthin)) ///
	(scatter y_britid d_britid, mcolor(gs6) msymbol(t) msize(medsmall)) ///
	(rspike dlow_britid dup_britid y_britid, lcolor(gs6) horizontal lwidth(medthin)) ///
	(scatter y_englid d_englid, mcolor(gs4) msymbol(d) msize(medsmall)) ///
	(rspike dlow_englid dup_englid y_englid, lcolor(gs4) horizontal lwidth(medthin)) ///
	, ///
		by(year, noixlabel ixtitle graphregion(fcolor(white) lcolor(white)) bgcolor(white) note("{it:Note:} The spikes represent 95% confidence intervals.") title("± 1 day", margin(bottom) span) legend(pos(2))) ///
	ytitle("") yscale(reverse  range(1 29.5) noline) ///
	ylabel(3 "Post * young" 9 "Post * degree" 15 "Post * male" 21 "Post * leftist" 27 "Post * undecided", labsize(8pt) angle(horizontal) nogrid) ///
	xtitle("Effect on political attitudes" "(Cohen's {it:d})", margin(small)) xscale(noline) xlabel(-.4(.1).4, tlcolor(black)) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	legend(order(1 3 5 7) label(1 "Tough security") label(3 "Anti-immigration") label(5 "British identity") label(7 "English identity") cols(1) size(small) colgap(*1) keygap(*1) region(lstyle(none) lcolor(white))) ///
	subtitle(, size(vlarge) align(middle) margin(bottom) nobox fcolor(white))  ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(6) ysize(3) 

* Manual edits
gr_edit .b1title.draw_view.setstyle, style(no)
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(show_labels(yes))) editcopy	
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
gr_edit .plotregion1.xaxis1[1].title.style.editstyle size(medium) editcopy
gr_edit .plotregion1.xaxis1[2].title.style.editstyle size(medium) editcopy
gr_edit .legend.yoffset = -8
gr_edit .gmetric_mult = 1.15



* Two-day comparison
use "SubGroup2017_2.dta", replace
append using "SubGroup2019_2.dta"
gen x1 = 10
gen x2 = 12.5
* Graph
twoway ///
	(scatter y_sec d_sec, mcolor(gs12) msymbol(o)) ///
	(rspike dlow_sec dup_sec y_sec, lcolor(gs12) horizontal) ///
	(scatter y_imm d_imm, mcolor(gs8) msymbol(s) msize(medsmall)) ///
	(rspike dlow_imm dup_imm y_imm, lcolor(gs8) horizontal lwidth(medthin)) ///
	(scatter y_britid d_britid, mcolor(gs6) msymbol(t) msize(medsmall)) ///
	(rspike dlow_britid dup_britid y_britid, lcolor(gs6) horizontal lwidth(medthin)) ///
	(scatter y_englid d_englid, mcolor(gs4) msymbol(d) msize(medsmall)) ///
	(rspike dlow_englid dup_englid y_englid, lcolor(gs4) horizontal lwidth(medthin)) ///
	, ///
		by(year, noixlabel ixtitle graphregion(fcolor(white) lcolor(white)) bgcolor(white) note("{it:Note:} The spikes represent 95% confidence intervals.") title("± 2 days", margin(bottom) span) legend(pos(2))) ///
	ytitle("") yscale(reverse  range(1 29.5) noline) ///
	ylabel(3 "Post * young" 9 "Post * degree" 15 "Post * male" 21 "Post * leftist" 27 "Post * undecided", labsize(8pt) angle(horizontal) nogrid) ///
	xtitle("Effect on political attitudes" "(Cohen's {it:d})", margin(small)) xscale(noline) xlabel(-.4(.1).4, tlcolor(black)) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	legend(order(1 3 5 7) label(1 "Tough security") label(3 "Anti-immigration") label(5 "British identity") label(7 "English identity") cols(1) size(small) colgap(*1) keygap(*1) region(lstyle(none) lcolor(white))) ///
	subtitle(, size(vlarge) align(middle) margin(bottom) nobox fcolor(white))  ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(6) ysize(3) 

* Manual edits
gr_edit .b1title.draw_view.setstyle, style(no)
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(show_labels(yes))) editcopy	
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
gr_edit .plotregion1.xaxis1[1].title.style.editstyle size(medium) editcopy
gr_edit .plotregion1.xaxis1[2].title.style.editstyle size(medium) editcopy
gr_edit .legend.yoffset = -8
gr_edit .gmetric_mult = 1.15



* Three-day comparison
use "SubGroup2017_3.dta", replace
append using "SubGroup2019_3.dta"
gen x1 = 6.5
gen x2 = 8.75

* Graph
twoway ///
	(scatter y_sec d_sec, mcolor(gs12) msymbol(o)) ///
	(rspike dlow_sec dup_sec y_sec, lcolor(gs12) horizontal) ///
	(scatter y_imm d_imm, mcolor(gs8) msymbol(s) msize(medsmall)) ///
	(rspike dlow_imm dup_imm y_imm, lcolor(gs8) horizontal lwidth(medthin)) ///
	(scatter y_britid d_britid, mcolor(gs6) msymbol(t) msize(medsmall)) ///
	(rspike dlow_britid dup_britid y_britid, lcolor(gs6) horizontal lwidth(medthin)) ///
	(scatter y_englid d_englid, mcolor(gs4) msymbol(d) msize(medsmall)) ///
	(rspike dlow_englid dup_englid y_englid, lcolor(gs4) horizontal lwidth(medthin)) ///
	, ///
		by(year, noixlabel ixtitle graphregion(fcolor(white) lcolor(white)) bgcolor(white) note("{it:Note:} The spikes represent 95% confidence intervals.") title("± 3 days", margin(bottom) span) legend(pos(2))) ///
	ytitle("") yscale(reverse  range(1 29.5) noline) ///
	ylabel(3 "Post * young" 9 "Post * degree" 15 "Post * male" 21 "Post * leftist" 27 "Post * undecided", labsize(16pt) angle(horizontal) nogrid) ///
	xtitle("Effect on political attitudes" "(Cohen's {it:d})", margin(small)) xscale(noline) xlabel(-.4(.1).4, tlcolor(black)) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	legend(order(1 3 5 7) label(1 "Tough security") label(3 "Anti-immigration") label(5 "British identity") label(7 "English identity") cols(1) size(small) colgap(*1) keygap(*1) region(lstyle(none) lcolor(white))) ///
	subtitle(, size(vlarge) align(middle) margin(bottom) nobox fcolor(white))  ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(12) ysize(6) 

* Manual edits
gr_edit .b1title.draw_view.setstyle, style(no)
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(show_labels(yes))) editcopy	
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
gr_edit .plotregion1.xaxis1[1].title.style.editstyle size(medium) editcopy
gr_edit .plotregion1.xaxis1[2].title.style.editstyle size(medium) editcopy
gr_edit .legend.yoffset = -8
gr_edit .gmetric_mult = 1.15







** Tidy Up
**********

erase "SubGroup2017.dta"
erase "SubGroup2019.dta"
erase "SubGroup2017_1.dta"
erase "SubGroup2019_1.dta"
erase "SubGroup2017_2.dta"
erase "SubGroup2019_2.dta"
erase "SubGroup2017_3.dta"
erase "SubGroup2019_3.dta"

